// license-header java merge-point
/**
 * This is only generated once! It will never be overwritten.
 * You can (and have to!) safely modify it by hand.
 */
package fr.upstlse.glre.business.domain.communiquer;


/**
 * @see fr.upstlse.glre.business.domain.communiquer.Message
 */
public class MessageDaoImpl
    extends fr.upstlse.glre.business.domain.communiquer.MessageDaoBase
{
    /**
     * @see fr.upstlse.glre.business.domain.communiquer.MessageDao#toMessageVO(fr.upstlse.glre.business.domain.communiquer.Message, fr.upstlse.glre.business.vo.communiquer.MessageVO)
     */
    public void toMessageVO(
        fr.upstlse.glre.business.domain.communiquer.Message source,
        fr.upstlse.glre.business.vo.communiquer.MessageVO target)
    {
        super.toMessageVO(source, target);
       target.setExpediteur(getUserDao().toUserVO(source.getExpediteur()));
       
        if(source.getParent() != null) {
        	target.setParent(toMessageVO(source.getParent()));
        }
    }


    /**
     * @see fr.upstlse.glre.business.domain.communiquer.MessageDao#toMessageVO(fr.upstlse.glre.business.domain.communiquer.Message)
     */
    public fr.upstlse.glre.business.vo.communiquer.MessageVO toMessageVO(final fr.upstlse.glre.business.domain.communiquer.Message entity)
    {
        return super.toMessageVO(entity);
    }


    /**
     * Retrieves the entity object that is associated with the specified value object
     * from the object store. If no such entity object exists in the object store,
     * a new, blank entity is created
     */
    private fr.upstlse.glre.business.domain.communiquer.Message loadMessageFromMessageVO(fr.upstlse.glre.business.vo.communiquer.MessageVO messageVO)
    {
        fr.upstlse.glre.business.domain.communiquer.Message message = this.load(messageVO.getId());
        if (message == null)
        {
            message = fr.upstlse.glre.business.domain.communiquer.Message.Factory.newInstance();
        }
        return message;
    }

    
    /**
     * @see fr.upstlse.glre.business.domain.communiquer.MessageDao#messageVOToEntity(fr.upstlse.glre.business.vo.communiquer.MessageVO)
     */
    public fr.upstlse.glre.business.domain.communiquer.Message messageVOToEntity(fr.upstlse.glre.business.vo.communiquer.MessageVO messageVO)
    {
        fr.upstlse.glre.business.domain.communiquer.Message entity = this.loadMessageFromMessageVO(messageVO);
        this.messageVOToEntity(messageVO, entity, false);
        return entity;
    }


    /**
     * @see fr.upstlse.glre.business.domain.communiquer.MessageDao#messageVOToEntity(fr.upstlse.glre.business.vo.communiquer.MessageVO, fr.upstlse.glre.business.domain.communiquer.Message)
     */
    public void messageVOToEntity(
        fr.upstlse.glre.business.vo.communiquer.MessageVO source,
        fr.upstlse.glre.business.domain.communiquer.Message target,
        boolean copyIfNull)
    {
        super.messageVOToEntity(source, target, copyIfNull);
        if (copyIfNull || source.getExpediteur() != null) {
        	target.setExpediteur(getUserDao().userVOToEntity(source.getExpediteur()));
        }
        if (copyIfNull || source.getParent() != null) {
        	Message lMessage = messageVOToEntity(source.getParent());
        	target.setParent(lMessage);
        }
    }
}